﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Xww.IO {
    public static class FilePathHelper {

        public static string GenerateRandomFilePath() {
            return Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
        }
        public static FileInfo[] GenerateRandomFiles(int count) {
            FileInfo[] rst = new FileInfo[count];
            for (int i = 0; i < rst.Length; i++) {
                rst[i] = new FileInfo(GenerateRandomFilePath());
            }
            return rst;
        }
        /// <summary>
        /// Return the directory name of a file path.
        /// </summary>
        public static string GetDirectory(this string filePath) {
            return Path.GetDirectoryName(filePath);
        }
        /// <summary>
        /// Determin whether a path be valid for save. (Based on whether its parent directory exists.)
        /// </summary>
        /// <param name="saveFilePath"></param>
        /// <returns></returns>
        public static bool IsValidSaveFilePath(this string saveFilePath) {
            return Directory.Exists(saveFilePath.GetDirectory());
        }
    }
}
